/*
 * Copyright (C) 2006-2015
 * 版权所有者为北京捷越联合信息咨询有限公司。本系统是商用软件,未经授权擅自复制或传播本程序的部分或全部将是非法的。
 * @title: SubsidiaryService.java
 * @package com.jy.modules.cims.subsidiary.service
 * @author zhaox
 * @date 2015-3-23 下午7:23:37
 * @version v1.00
 * @description: TODO(用一句话描述该文件做什么)
 */

package com.jy.modules.cims.subsidiary.service;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.jy.modules.cims.common.sysUtils.SearchParamUtil;
import com.jy.modules.cims.data.dao.LoanDao;
import com.jy.modules.cims.data.dao.SubsidiaryDao;
import com.jy.modules.cims.data.dto.CooperorgFormCreditTotalDto;
import com.jy.modules.cims.data.dto.form.tbj.TbjRaisePlanTotalDto;
import com.jy.modules.cims.data.dto.form.tbj.TbjAuditResulTotalDto;
import com.jy.modules.cims.data.dto.form.tbj.TbjLoanResulTotalDto;
import com.jy.modules.cims.data.interact.core.loan.request.ReportQueryDTO;
import com.jy.modules.cims.data.interact.core.loan.response.AdanceRepaymentDTO;
import com.jy.modules.cims.data.interact.core.loan.response.BankAcctChangeDTO;
import com.jy.modules.cims.data.interact.core.loan.response.NoWithholdingActiveRepaymentDTO;
import com.jy.modules.cims.data.interact.core.loan.response.SettlementDTO;
import com.jy.modules.cims.interact.CIRLoanIFImpl;
import com.jy.modules.cims.interact.IInteractAssist;
import com.jy.modules.cims.interact.InteractClassInvokeService;

/**
 * @classname: SubsidiaryService
 * @description: TODO(这里用一句话描述这个类的作用)
 */
@Service("com.jy.modules.cims.subsidiary.service.SubsidiaryService")
public class SubsidiaryService {

    @Autowired
    @Qualifier("com.jy.modules.cims.interact.CIRLoanIFImpl")
    public CIRLoanIFImpl cIRLoanIFImpl;

    @Autowired
    private SubsidiaryDao subsidiaryDao;

    @Autowired
    private LoanDao loanDao;

    @Autowired
    @Qualifier("com.jy.modules.cims.interact.CInteractAssist")
    private IInteractAssist iInteractAssist;

    @Autowired
    @Qualifier("com.jy.modules.cims.interact.InteractClassInvokeService")
    private InteractClassInvokeService interactClassInvokeService;

    /**
     * 查询核心非代扣主动还款(认款)信息
     * 
     * @title: queryNoWithholdingActiveRepayment
     * @author
     * @description:
     * @date 2015-3-23 上午9:41:24
     * @param reportQueryDTO
     * @return
     * @throws
     */
    public List<NoWithholdingActiveRepaymentDTO> queryNoWithholdingActiveRepayment(ReportQueryDTO reportQueryDTO) {
        String busiNoForInteract = iInteractAssist.getInteractNo();
        reportQueryDTO.setDealCode(busiNoForInteract);// 交易流水
        iInteractAssist.registerDealIrtService(busiNoForInteract);
        List<NoWithholdingActiveRepaymentDTO> list = cIRLoanIFImpl.queryNoWithholdingActiveRepayment(reportQueryDTO);
        if (list != null && !list.isEmpty())
            for (NoWithholdingActiveRepaymentDTO noWithholdingActiveRepaymentDTO : list) {
                Map<String, String> map = subsidiaryDao.queryNoWithholdingActiveRepayment(SearchParamUtil
                        .getSearchParam(noWithholdingActiveRepaymentDTO));
                if (map != null) {
                    noWithholdingActiveRepaymentDTO.setAcctBankName(map.get("acctbankname".toUpperCase()) == null ? ""
                            : map.get("acctbankname".toUpperCase()).toString());
                    noWithholdingActiveRepaymentDTO.setBorrower(map.get("BORROWER") == null ? "" : map.get("BORROWER")
                            .toString());
                    noWithholdingActiveRepaymentDTO.setId(map.get("ID") == null ? "" : map.get("ID").toString());
                    noWithholdingActiveRepaymentDTO.setRepaymentWay(map.get("repaymentway".toUpperCase()) == null ? ""
                            : map.get("repaymentway".toUpperCase()).toString());
                }
            }
        return list;
    }

    /**
     * 查询核心一次性结清提前还款明细
     * 
     * @title: queryAdvancFinish
     * @author
     * @description:
     * @date 2015-3-23 上午9:41:24
     * @param reportQueryDTO
     * @return
     * @throws
     */
    public List<SettlementDTO> queryAdvancFinish(Map<String, Object> map) {
//        String busiNoForInteract = iInteractAssist.getInteractNo();
//        reportQueryDTO.setDealCode(busiNoForInteract);// 交易流水
//        iInteractAssist.registerDealIrtService(busiNoForInteract);
//        List<SettlementDTO> list = cIRLoanIFImpl.queryAdvancFinish(reportQueryDTO);
//        // SettlementDTO s = new SettlementDTO();
//        // list.add(s);
//        if (list != null && !list.isEmpty())
//            for (SettlementDTO settlementDTO : list) {
//                // settlementDTO.setContractNo("123x");
//                Map<String, String> map = subsidiaryDao
//                        .queryAdvancFinish(SearchParamUtil.getSearchParam(settlementDTO));
//                if (map != null) {
//                    settlementDTO.setBorrower(map.get("BORROWER") == null ? "" : map.get("BORROWER").toString());
//                    settlementDTO.setId(map.get("ID") == null ? "" : map.get("ID").toString());
//                    settlementDTO.setRepayDate(map.get("REPAYDATE") == null ? "" : map.get("REPAYDATE").toString());
//                    settlementDTO.setType(map.get("TYPE") == null ? "" : map.get("TYPE").toString());// 提前还清类型
//                    settlementDTO.setRepayType(map.get("REPAYTYPE") == null ? "" : map.get("REPAYTYPE").toString());
//                    settlementDTO.setFee("");// 信托服务费
//                }
//            }
//        return list;
        return subsidiaryDao.payOff(map);
    }

    /**
     * 查询核心银行账户变更信息
     * 
     * @title: queryBankAcctChange
     * @author
     * @description:
     * @date 2015-3-23 上午9:41:24
     * @param reportQueryDTO
     * @return
     * @throws
     */
    public List<BankAcctChangeDTO> queryBankAcctChange(Map<String, Object> map) {
//        String busiNoForInteract = iInteractAssist.getInteractNo();
//        reportQueryDTO.setDealCode(busiNoForInteract);// 交易流水
//        iInteractAssist.registerDealIrtService(busiNoForInteract);
//        List<BankAcctChangeDTO> list = cIRLoanIFImpl.queryBankAcctChange(reportQueryDTO);
//        if (list != null && !list.isEmpty())
//            for (BankAcctChangeDTO bankAcctChangeDTO : list) {
//                Map<String, String> map = subsidiaryDao.queryBankAcctChange(SearchParamUtil
//                        .getSearchParam(bankAcctChangeDTO));
//                if (map != null) {
//                    bankAcctChangeDTO.setBorrower(map.get("BORROWER") == null ? "" : map.get("BORROWER").toString());
//                    bankAcctChangeDTO.setId(map.get("ID") == null ? "" : map.get("ID").toString());
//                    bankAcctChangeDTO.setBankName("");//
//                    bankAcctChangeDTO.setBranchBankName("");//
//                    bankAcctChangeDTO.setOtherPay("");//
//                    bankAcctChangeDTO.setUrl("");//
//                }
//            }
//        return list;
        return subsidiaryDao.changeAccount(map);
    }

    /**
     * 查询核心预缴提前还款明细信息
     * 
     * @title: queryAdvanceRepayment
     * @author
     * @description:
     * @date 2015-3-23 上午9:41:24
     * @param reportQueryDTO
     * @return
     * @throws
     */
    public List<AdanceRepaymentDTO> queryAdvanceRepayment(Map<String, Object> map) {
//        String busiNoForInteract = iInteractAssist.getInteractNo();
//        reportQueryDTO.setDealCode(busiNoForInteract);// 交易流水
//        iInteractAssist.registerDealIrtService(busiNoForInteract);
//        List<AdanceRepaymentDTO> list = cIRLoanIFImpl.queryAdvanceRepayment(reportQueryDTO);
//        if (list != null && !list.isEmpty())
//            for (AdanceRepaymentDTO adanceRepaymentDTO : list) {
//                Map<String, String> map = subsidiaryDao.queryAdvanceRepayment(SearchParamUtil
//                        .getSearchParam(adanceRepaymentDTO));
//                if (map != null) {
//                    adanceRepaymentDTO.setBorrower(map.get("BORROWER") == null ? "" : map.get("BORROWER").toString());
//                    adanceRepaymentDTO.setId(map.get("ID") == null ? "" : map.get("ID").toString());
//                    adanceRepaymentDTO
//                            .setRepayDate(map.get("REPAYDATE") == null ? "" : map.get("REPAYDATE").toString());
//                    adanceRepaymentDTO.setPrepayDate("");//
//                    adanceRepaymentDTO.setRepaymentWay(map.get("REPAYMENTWAY") == null ? "" : map.get("REPAYMENTWAY")
//                            .toString());
//                }
//            }
//        return list;
        return subsidiaryDao.prepayAdvance(map);
    }

    public List<Map<String, Object>> queryRefuseLoan(Map<String, Object> map) {
        return loanDao.getLoanDetail(map);
    }

    /**
     * 非代扣主动还款清单
     * 
     * @title: queryRepaymentInfo_Xt
     * @author
     * @description:
     * @date 2015-8-24 上午10:22:57
     * @param map
     * @return
     * @throws
     */
    public List<Map<String, Object>> queryRepaymentInfo_Xt(Map<String, Object> map) {
        return subsidiaryDao.nonDK(map);
    }

    /**
     * 预缴提前还款后提款明细视图
     * 
     * @title: queryPrerepayDraw_Detail
     * @author
     * @description:
     * @date 2015-8-24 上午10:23:00
     * @param map
     * @return
     * @throws
     */
    public List<Map<String, Object>> queryPrerepayDraw_Detail(Map<String, Object> map) {
        return subsidiaryDao.prerePayDraw(map);
    }

    /**
     * 统计查询合作机构的在途、转让、赎回、二次购买的债权价值
     * 
     * @param map
     * @return
     */
    public List<CooperorgFormCreditTotalDto> getCooperorgFormTotalByDay(Map<String, Object> map) {

        return subsidiaryDao.getCooperorgFormTotalByDayByPaging(map);
    }
    
    /**
     * 统计查询铜板街审核结果
     * 
     * @param map
     * @return
     */
    public List<TbjAuditResulTotalDto> getTbjAuditResult(Map<String, Object> map){

        return subsidiaryDao.getTbjAuditResultByPaging(map);
    }
    
    /**
     * 统计查询铜板街放款结果
     * 
     * @param map
     * @return
     */
    public List<TbjLoanResulTotalDto> getTbjLoanResult(Map<String, Object> map) {

        return subsidiaryDao.getTbjLoanResultByPaging(map);
    }
    /**
     * 募集计划与贷款转出包对照关系
     * 
     * @param map
     * @return
     */
    public List<TbjRaisePlanTotalDto> getTbjRaisePlanAndLoanByPaging(Map<String, Object> map) {

        return subsidiaryDao.getTbjRaisePlanAndLoanByPaging(map);
    }
    /**
     * 募集计划与贷款转出包对照关系导出
     * 
     * @param map
     * @return
     */
    public List<TbjRaisePlanTotalDto> exportTbjRaisePlanAndLoan(Map<String, Object> map) {

        return subsidiaryDao.exportTbjRaisePlanAndLoan(map);
    }
}
